package com.example.gustavo.hello.task;

import java.util.TimerTask;

/**
 * 任务类
 * Created by gustavo on 2015/1/5.
 */
public class MsgTask extends TimerTask {
    private long deltaTime;  //时间增量，及任务执行等待时间
    private MsgKey msgKey;
    private MsgProcessor msgProcessor = new MsgProcessor();

    public MsgTask(MsgKey msgKey,long deltaTime) {
        super();
        this.msgKey = msgKey;
        this.deltaTime = deltaTime;
    }

    public long getDeltaTime() {
        return deltaTime;
    }

    public void setDeltaTime(long deltaTime) {
        this.deltaTime = deltaTime;
    }

    public MsgKey getMsgKey() {
        return msgKey;
    }

    public void setMsgKey(MsgKey msgKey) {
        this.msgKey = msgKey;
    }

    @Override
    public void run() {//等待时间到了以后，就执行
        int index = msgKey.getIndex();
        msgProcessor.dealOverTimeMsg(index);
        MsgManager.removeMsgTask(msgKey);
        this.cancel();
    }

}